package slice

import "fmt"

func update(s []int)  {
	s[0] = 200
}
func main() {
	arr := [...]int{1,2,3,4,5,6,7,8}
	s := arr[2:6]
	fmt.Println(s)
	
	fmt.Println(arr[2:6])
	fmt.Println(arr[:6])
	s1 := arr[2:]
	fmt.Println("s1 = ", s1)
	s2 := arr[:]
	fmt.Println("s2 = ", s2)
	
	update(s1)
	update(s2)
	
	fmt.Println(s1, s2)
	
	
	fmt.Println("Reslice:")
	fmt.Println(s2)
	
	s2 = s2[:5]
	fmt.Println(s2)
	
	s2 = s2[2:]
	fmt.Println(s2)


	//slice 的扩展

	fmt.Println("Extending slice")
	arr4 := [...]int{0,1,2,3,4,5,6,7}
	s1 = arr4[2:6]
	s2 = s1[3:5]

	fmt.Println("s1 = ", s1)
	fmt.Println("s2 = ", s2)


	fmt.Printf("s1 = %v, len(s1) = %d, cap(s1) = %d \n", s1, len(s1), cap(s1))
	fmt.Printf("s2 = %v, len(s2) = %d, cap(s2) = %d \n", s2, len(s2), cap(s2))

	fmt.Println("--------------line------------------\n")

	s3 := append(s2, 10)
	s4 := append(s3, 11)
	s5 := append(s4, 12)
	//s4 and s5 no longer view arr
	fmt.Println("s3, s4, s5 = ", s3, s4, s5)
}
